<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>Convert Processor | ElasticSearch 7.7 权威指南中文版</title>
	<meta name="keywords" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <meta name="description" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
	<link rel="stylesheet" type="text/css" href="../static/styles.css" />
	<script>
	var _link = 'convert-processor.html';
    </script>
</head>
<body>
<div class="main-container">
    <section id="content">
        <div class="content-wrapper">
            <section id="guide" lang="zh_cn">
                <div class="container">
                    <div class="row">
                        <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                            <div style="color:gray; word-break: break-all; font-size:12px;">原英文版地址: <a href="https://www.elastic.co/guide/en/elasticsearch/reference/7.7/convert-processor.html" rel="nofollow" target="_blank">https://www.elastic.co/guide/en/elasticsearch/reference/7.7/convert-processor.html</a>, 原文档版权归 www.elastic.co 所有<br/>本地英文版地址: <a href="../en/convert-processor.html" rel="nofollow" target="_blank">../en/convert-processor.html</a></div>
                        <!-- start body -->
                  <div class="page_header">
<strong>重要</strong>: 此版本不会发布额外的bug修复或文档更新。最新信息请参考 <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html" rel="nofollow">当前版本文档</a>。
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch Guide [7.7]</a></span>
»
<span class="breadcrumb-link"><a href="ingest.html">Ingest node</a></span>
»
<span class="breadcrumb-link"><a href="ingest-processors.html">Processors</a></span>
»
<span class="breadcrumb-node">Convert Processor</span>
</div>
<div class="navheader">
<span class="prev">
<a href="ingest-circle-processor.html">« Circle Processor</a>
</span>
<span class="next">
<a href="csv-processor.html">CSV Processor »</a>
</span>
</div>
<div class="section">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="convert-processor"></a>Convert Processor<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/ingest/processors/convert.asciidoc">edit</a>
</h2>
</div></div></div>
<p>Converts a field in the currently ingested document to a different type, such as converting a string to an integer.
If the field value is an array, all members will be converted.</p>
<p>The supported types include: <code class="literal">integer</code>, <code class="literal">long</code>, <code class="literal">float</code>, <code class="literal">double</code>, <code class="literal">string</code>, <code class="literal">boolean</code>, and <code class="literal">auto</code>.</p>
<p>Specifying <code class="literal">boolean</code> will set the field to true if its string value is equal to <code class="literal">true</code> (ignore case), to
false if its string value is equal to <code class="literal">false</code> (ignore case), or it will throw an exception otherwise.</p>
<p>Specifying <code class="literal">auto</code> will attempt to convert the string-valued <code class="literal">field</code> into the closest non-string type.
For example, a field whose value is <code class="literal">"true"</code> will be converted to its respective boolean type: <code class="literal">true</code>. Do note
that float takes precedence of double in <code class="literal">auto</code>. A value of <code class="literal">"242.15"</code> will "automatically" be converted to
<code class="literal">242.15</code> of type <code class="literal">float</code>. If a provided field cannot be appropriately converted, the Convert Processor will
still process successfully and leave the field value as-is. In such a case, <code class="literal">target_field</code> will
still be updated with the unconverted field value.</p>
<div class="table">
<a id="convert-options"></a>
<p class="title"><strong>Table 36. Convert Options</strong></p>
<div class="table-contents">
<table border="1" cellpadding="4px" summary="Convert Options">
<colgroup>
<col class="col_1">
<col class="col_2">
<col class="col_3">
<col class="col_4">
</colgroup>
<thead>
<tr>
<th align="left" valign="top">Name</th>
<th align="left" valign="top">Required</th>
<th align="left" valign="top">Default</th>
<th align="left" valign="top">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left" valign="top"><p><code class="literal">field</code></p></td>
<td align="left" valign="top"><p>yes</p></td>
<td align="left" valign="top"><p>-</p></td>
<td align="left" valign="top"><p>The field whose value is to be converted</p></td>
</tr>
<tr>
<td align="left" valign="top"><p><code class="literal">target_field</code></p></td>
<td align="left" valign="top"><p>no</p></td>
<td align="left" valign="top"><p><code class="literal">field</code></p></td>
<td align="left" valign="top"><p>The field to assign the converted value to, by default <code class="literal">field</code> is updated in-place</p></td>
</tr>
<tr>
<td align="left" valign="top"><p><code class="literal">type</code></p></td>
<td align="left" valign="top"><p>yes</p></td>
<td align="left" valign="top"><p>-</p></td>
<td align="left" valign="top"><p>The type to convert the existing value to</p></td>
</tr>
<tr>
<td align="left" valign="top"><p><code class="literal">ignore_missing</code></p></td>
<td align="left" valign="top"><p>no</p></td>
<td align="left" valign="top"><p><code class="literal">false</code></p></td>
<td align="left" valign="top"><p>If <code class="literal">true</code> and <code class="literal">field</code> does not exist or is <code class="literal">null</code>, the processor quietly exits without modifying the document</p></td>
</tr>
<tr>
<td align="left" valign="top"><p><code class="literal">if</code></p></td>
<td align="left" valign="top"><p>no</p></td>
<td align="left" valign="top"><p>-</p></td>
<td align="left" valign="top"><p>Conditionally execute this processor.</p></td>
</tr>
<tr>
<td align="left" valign="top"><p><code class="literal">on_failure</code></p></td>
<td align="left" valign="top"><p>no</p></td>
<td align="left" valign="top"><p>-</p></td>
<td align="left" valign="top"><p>Handle failures for this processor. See <a class="xref" href="handling-failure-in-pipelines.html" title="Handling Failures in Pipelines"><em>Handling Failures in Pipelines</em></a>.</p></td>
</tr>
<tr>
<td align="left" valign="top"><p><code class="literal">ignore_failure</code></p></td>
<td align="left" valign="top"><p>no</p></td>
<td align="left" valign="top"><p><code class="literal">false</code></p></td>
<td align="left" valign="top"><p>Ignore failures for this processor. See <a class="xref" href="handling-failure-in-pipelines.html" title="Handling Failures in Pipelines"><em>Handling Failures in Pipelines</em></a>.</p></td>
</tr>
<tr>
<td align="left" valign="top"><p><code class="literal">tag</code></p></td>
<td align="left" valign="top"><p>no</p></td>
<td align="left" valign="top"><p>-</p></td>
<td align="left" valign="top"><p>An identifier for this processor. Useful for debugging and metrics.</p></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="pre_wrapper lang-js">
<pre class="programlisting prettyprint lang-js">PUT _ingest/pipeline/my-pipeline-id
{
  "description": "converts the content of the id field to an integer",
  "processors" : [
    {
      "convert" : {
        "field" : "id",
        "type": "integer"
      }
    }
  ]
}</pre>
</div>
</div>
<div class="navfooter">
<span class="prev">
<a href="ingest-circle-processor.html">« Circle Processor</a>
</span>
<span class="next">
<a href="csv-processor.html">CSV Processor »</a>
</span>
</div>
</div>

                  <!-- end body -->
                        </div>
                        <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                        
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </section>
</div>
<script src="../static/cn.js"></script>
</body>
</html>